//package org.stone.project.webIntegration.filter;
//
//import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
//import org.springframework.core.annotation.Order;
//import org.springframework.http.HttpMethod;
//import org.springframework.stereotype.Component;
//
//import javax.servlet.*;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//
///**
// * options请求拦截
// */
//@Order(Integer.MIN_VALUE)
//@Component
//@ConditionalOnProperty(name = "options.filter.enabled",havingValue = "true", matchIfMissing = true)
//public class OptionsFilter implements Filter {
//    @Override
//    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
//        HttpServletResponse httpResponse = (HttpServletResponse) servletResponse;
//        HttpServletRequest httpRequest = (HttpServletRequest) servletRequest;
//        String method = httpRequest.getMethod();
//        if (HttpMethod.OPTIONS.name().equals(method)){
//            // 设置允许的来源
//            httpResponse.setHeader("Access-Control-Allow-Origin", "*");
//            // 设置允许的方法
//            httpResponse.setHeader("Access-Control-Allow-Methods", "*");
//            // 设置允许的头信息
//            httpResponse.setHeader("Access-Control-Allow-Headers", "*");
//            // 设置预检请求的有效期
//            httpResponse.setHeader("Access-Control-Max-Age", "360000");
//
//            // 对于 OPTIONS 请求，返回 200 OK
//            httpResponse.setStatus(HttpServletResponse.SC_OK);
//            return;
//        }
//
//        // 继续执行过滤链
//        filterChain.doFilter(servletRequest, servletResponse);
//    }
//}
